pub mod cie;
pub mod relocation;
pub mod str_tab;
pub mod symbol;
use bits::field::{BufferReader, BufferWriter};

use super::{Elf64Addr, Elf64Off, Elf64Word, Elf64Xword};

#[repr(C)]
#[derive(Default)]
pub struct Header {
    pub name: Elf64Word,
    pub sec_type: SecType,
    pub flags: SectionFlag,
    pub addr: Elf64Addr,
    pub offset: Elf64Off,
    pub size: Elf64Xword,
    pub link: Elf64Word,
    pub info: Elf64Word,
    pub addralign: Elf64Xword,
    pub entsize: Elf64Xword,
}

impl_borrow!(Header);

trans! {
    #[derive(Default)]
    SecType:u32,
    #[derive(Default)]
    SectionFlag: u64,
}

def_const! {
    SecType {
        NULL: 0,
        PROGBITS: 1,
        SYMTAB: 2,
        STRTAB: 3,
        RELA: 4,
        HASH: 5,
        DYNAMIC: 6,
        NOTE: 7,
        NOBITS: 8,
        REL: 9,
        SHLIB: 10,
        DYNSYM: 11,
    }
}

impl BufferReader for SectionFlag {}
impl BufferWriter for SectionFlag {}

pub mod flags {
    bits::fields_ex! {
        super::SectionFlag [data] {
            WRITE       [00, rw, bool],
            ALLOC       [01, rw, bool],
            EXECINSTR   [02, rw, bool],
            Amd64Large  [28, rw, bool]
        }
    }
}
